package org.origin.ferret.system.mapstruct;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.origin.centre.model.enums.XDisplay;
import org.origin.centre.model.enums.XUsable;
import org.origin.centre.support.utils.EnumUtil;
import org.origin.ferret.system.model.dto.menu.SysMenuInsertDto;
import org.origin.ferret.system.model.dto.menu.SysMenuUpdateDto;
import org.origin.ferret.system.model.entity.SysMenuEntity;
import org.origin.ferret.system.model.enums.MenuTypeEnum;
import org.origin.ferret.system.model.vo.menu.SysMenuVo;

import java.util.List;

/**
 * 系统菜单对象-转换
 *
 * @author ferret
 * @version 2024-05-08
 */
@Mapper(componentModel = "spring")
public interface SysMenuMapstruct {

    SysMenuEntity toEntity(SysMenuInsertDto insertDto);

    SysMenuEntity toEntity(SysMenuUpdateDto updateDto);

    List<SysMenuVo> toVos(List<SysMenuEntity> entities);

    @Mapping(target = "typeLabel", expression = "java(getTypeLabel(entity.getType()))")
    @Mapping(target = "displayLabel", expression = "java(getDisplayLabel(entity.getDisplay()))")
    @Mapping(target = "statusLabel", expression = "java(getStatusLabel(entity.getStatus()))")
    SysMenuVo toVo(SysMenuEntity entity);


    default String getTypeLabel(Integer type) {
        return EnumUtil.getTitle(MenuTypeEnum.class, type);
    }

    default String getDisplayLabel(Integer display) {
        return EnumUtil.getTitle(XDisplay.class, display);
    }

    default String getStatusLabel(Integer status) {
        return EnumUtil.getTitle(XUsable.class, status);
    }
}
